import { createApp } from "vue";
import LoaderCo from "@/components/LoaderCo.vue";

let loadingInstance:any;

//註冊成全局變量使用
const LoadingService = {
    open(){
        if(!loadingInstance){
            //掛載
           const loadingApp = createApp(LoaderCo)
           const mountNode = document.createElement('div')
           document.body.appendChild(mountNode)
           loadingInstance = loadingApp.mount(mountNode)
        }
        loadingInstance.open()
    },
    close(){
        if(loadingInstance){
            loadingInstance.close()
        }
    }
}

export default LoadingService